<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<script type="text/javascript">
$(function() {
    $('#cms_channeltype_datagrid').datagrid({
        url : '${pageContext.request.contextPath}/channeltypeController/datagrid.action',
        fit : true,
        fitColumns : true,
        border : false,
        pagination : true,
        idField : 'id',
        pageSize : 10,
        pageList : [ 10, 20, 30, 40, 50 ],
        sortName : 'id',
        sortOrder : 'asc',
        checkOnSelect : false,
        selectOnCheck : false,
        nowrap : false,
        frozenColumns : [ [ {
            title : '编号',
            field : 'id',
            width : 150,
            sortable : true,
            checkbox : true
        }, {
            title : '频道名称',
            field : 'typename',
            width : 150,
            sortable : true
        },{
            title : '识别名称',
            field : 'nid',
            width : 150,
            sortable : true
        }] ],
        columns : [ [
            {
                title : '模型类型',
                field : 'issystem',
                width : 150,
                sortable : true,
                formatter:function(value,row,index){
                    if(value==1){
                        return "系统模型";
                    }else{
                        return "自建模型";
                    }
                }
            },
            {
                title : '状态',
                field : 'isshow',
                width : 150,
                sortable : true,
                formatter:function(value,row,index){
                    if(value==1){
                        return "启用";
                    }else{
                        return "禁用";
                    }
                }
            },{
                field : 'action',
                title : '操作',
                width : 100,
                formatter : function(value, row, index) {
                    return formatString('<img onclick="cms_channeltype_editFun(\'{0}\');" src="{1}"/>&nbsp;<img onclick="cms_channeltype_deleteFun(\'{2}\');" src="{3}"/>', row.id, '${pageContext.request.contextPath}/style/images/extjs_icons/pencil.png', row.id, '${pageContext.request.contextPath}/style/images/extjs_icons/cancel.png');
                }
            } ] ],
        toolbar : '#cms_channeltype_toolbar'
    });
});

function cms_channeltype_showNoteFun(index) {
    var rows = $('#cms_channeltype_datagrid').datagrid('getRows');
    var row = rows[index];
    $('<div/>').dialog({
        title : 'BUG名称[' + row.name + ']',
        modal : true,
        maximizable : true,
        width : 640,
        height : 480,
        content : '<iframe src="${pageContext.request.contextPath}/bugController/showNote.action?id=' + row.id + '" frameborder="0" style="border:0;width:100%;height:99%;"></iframe>',
        onClose : function() {
            $(this).dialog('destroy');
        }
    });

    $('#cms_channeltype_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
}

function cms_channeltype_editFun(id) {
    $('#cms_channeltype_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
    $('<div/>').dialog({
        href : '${pageContext.request.contextPath}/channeltypeController/toEdit.action?id=' + id,
        width : 500,
        height : 500,
        modal : true,
        title : '编辑',
        buttons : [ {
            text : '编辑',
            iconCls : 'icon-edit',
            handler : function() {
                var d = $(this).closest('.window-body');
                $('#cms_channeltypeEdit_editForm').form({
                    url : '${pageContext.request.contextPath}/channeltypeController/edit.action',
                    success : function(result) {
                        try {
                            var r = $.parseJSON(result);
                            if (r.success) {
                                $('#cms_channeltype_datagrid').datagrid('updateRow', {
                                    index : $('#cms_channeltype_datagrid').datagrid('getRowIndex', id),
                                    row : r.obj
                                });
                                d.dialog('destroy');
                            }
                            $.messager.show({
                                title : '提示',
                                msg : r.msg
                            });
                        } catch (e) {
                            $.messager.alert('提示', result);
                        }
                    }
                });
                $('#cms_channeltypeEdit_editForm').submit();
            }
        } ],
        onClose : function() {
            $(this).dialog('destroy');
        },
        onLoad : function() {
        }
    });
}
function cms_channeltype_appendFun() {
    $('#cms_channeltype_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
    $('<div/>').dialog({
        href : '${pageContext.request.contextPath}/channeltypeController/toAdd.action',
        width : 500,
        height : 500,
        modal : true,
        title : '添加BUG',
        buttons : [ {
            text : '增加',
            iconCls : 'icon-add',
            handler : function() {
                var d = $(this).closest('.window-body');
                $('#cms_channeltypeAdd_addForm').form({
                    url : '${pageContext.request.contextPath}/channeltypeController/add.action',
                    success : function(result) {
                        try {
                            var r = $.parseJSON(result);
                            if (r.success) {
                                $('#cms_channeltype_datagrid').datagrid('insertRow', {
                                    index : 0,
                                    row : r.obj
                                });
                                d.dialog('destroy');
                            }
                            $.messager.show({
                                title : '提示',
                                msg : r.msg
                            });
                        } catch (e) {
                            $.messager.alert('提示', result);
                        }
                    }
                });
                $('#cms_channeltypeAdd_addForm').submit();
            }
        } ],
        onClose : function() {
            $(this).dialog('destroy');
        }
    });
}
function cms_channeltype_removeFun() {
    var rows = $('#cms_channeltype_datagrid').datagrid('getChecked');
    var ids = [];
    if (rows.length > 0) {
        $.messager.confirm('确认', '您是否要删除当前选中的项目？', function(r) {
            if (r) {
                for ( var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                $.ajax({
                    url : '${pageContext.request.contextPath}/channeltypeController/remove.action',
                    data : {
                        ids : ids.join(',')
                    },
                    dataType : 'json',
                    success : function(result) {
                        if (result.success) {
                            $('#cms_channeltype_datagrid').datagrid('load');
                            $('#cms_channeltype_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
                        }
                        $.messager.show({
                            title : '提示',
                            msg : result.msg
                        });
                    }
                });
            }
        });
    } else {
        $.messager.show({
            title : '提示',
            msg : '请勾选要删除的记录！'
        });
    }
}
function cms_channeltype_deleteFun(id) {
    $('#cms_channeltype_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
    $('#cms_channeltype_datagrid').datagrid('checkRow', $('#cms_channeltype_datagrid').datagrid('getRowIndex', id));
    cms_channeltype_removeFun();
}
</script>
<table id="cms_channeltype_datagrid"></table>
<div id="cms_channeltype_toolbar" style="display: none;">
    <a href="javascript:void(0);" onclick="cms_channeltype_appendFun();" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="float: left;">增加</a>
    <div class="datagrid-btn-separator"></div>
    <a href="javascript:void(0);" onclick="cms_channeltype_removeFun();" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" style="float: left;">批量删除</a>
    <div class="datagrid-btn-separator"></div>
    <input id="cms_channeltype_searchbox" class="easyui-searchbox" style="width:150px;" data-options="searcher:function(value,name){$('#cms_channeltype_datagrid').datagrid('load',{channelTypeName:value});},prompt:'可模糊查询'" /> <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="$('#cms_channeltype_datagrid').datagrid('load',{});$('#cms_channeltype_searchbox').searchbox('setValue','');">清空条件</a>
</div>